﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Utils
{
    /// <summary>
    /// represents a value range checker
    /// </summary>
    public sealed class ValueRangeChecker
    {
        private const string ZeroRangeExceptionContent = "value cannot be zero";

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        public static void CheckZeroRange(int value) {
            if(value == 0) {
                throw new ArgumentException(ZeroRangeExceptionContent);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        public static void CheckZeroRange(float value) {
            if(value == 0f) {
                throw new ArgumentException(ZeroRangeExceptionContent);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        public static void CheckZeroRange(double value) {
            if (value == 0d) {
                throw new ArgumentException(ZeroRangeExceptionContent);
            }
        }


        private const string EmptyStringExceptionContent = "text cannot be null or empty";
        private const string WhiteSpaceStringExceptionContent = "text cannot be null or a contains white space only string";

        /// <summary>
        /// 
        /// </summary>
        /// <param name="text"></param>
        public static void CheckEmptyString(string text) {
            if (string.IsNullOrEmpty(text)) {
                throw new ArgumentException(EmptyStringExceptionContent);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="text"></param>
        public static void CheckWhiteSpaceString(string text) {
            if (string.IsNullOrWhiteSpace(text)) {
                throw new ArgumentException(EmptyStringExceptionContent);
            }
        }


        private const string ArrayRangeUnexpectedExceptionContent = "array cannot be null or empty";
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="array"></param>
        public static void CheckArrayRange<T>(T[] array) {
            if(array == null || array.Length == 0) {
                throw new ArgumentException(ArrayRangeUnexpectedExceptionContent);
            }
        }

        private const string NullRefExceptionContent = "parameter cannot be null";

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        public static void CheckNullParameter<T>(T value) 
            where T:class{
            if(value == null) {
                throw new ArgumentNullException(NullRefExceptionContent);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <param name="content"></param>
        public static void CheckNullParameter<T>(T value,string content)
            where T : class {
            if (value == null) {
                throw new ArgumentNullException(content);
            }
        }
    }
}
